package com.company.OfferGuide;

import com.company.ListNode;

public class 删除链表的节点 {

    public ListNode deleteNode(ListNode head, int val) {
        if (head == null) return null;
        if (head.val == val) return head.next;
        ListNode p = head,pre = head;
        while (p != null) {
            if (p.val == val) {
                pre.next = pre.next.next;
                break;
            }
            pre = p;
            p = p.next;
        }
        return head;
    }

}
